package com.solution.admin.company.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.solution.admin.company.dao.CompanyInvoiceDao;
import com.solution.admin.company.entity.CompanyInvoiceEntity;
import com.solution.admin.company.service.CompanyInvoiceService;
import com.solution.common.dao.BaseDao;
import com.solution.common.service.impl.BaseServiceImpl;

/**
 * 公司开票信息service实现
 * @author xkl
 * @date 2018年1月26日 下午3:34:57
 */
@Service
public class CompanyInvoiceServiceImpl extends BaseServiceImpl<CompanyInvoiceEntity> implements CompanyInvoiceService {

	@Autowired
	private CompanyInvoiceDao companyInvoiceDao;
	
	@Override
	protected BaseDao<CompanyInvoiceEntity> getDao() {
		return this.companyInvoiceDao;
	}

	/**
	 * 设置默认发票信息
	 * @param invoiceId
	 * @return
	 * @author xkl
	 * @date 2018年1月28日 下午12:20:38
	 */
	@Override
	@Transactional(rollbackFor=Exception.class)
	public Integer updateDefaultInvoice(CompanyInvoiceEntity invoiceEntity) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		if (null != invoiceEntity.getIsDefault() && invoiceEntity.getIsDefault() == 1) {
			paramMap.put("companyId", invoiceEntity.getCompanyId());
			companyInvoiceDao.updateNoDefaultInvoice(paramMap);
		}
		paramMap.put("id", invoiceEntity.getId());
		paramMap.put("modifier", invoiceEntity.getModifier());
		return companyInvoiceDao.updateDefaultInvoice(paramMap);
	}

	/**
	 * 根据公司名称与ID获取发票信息
	 * @param companyId
	 * @param companyName
	 * @return
	 * @author xkl
	 * @date 2018年3月6日 下午4:12:43
	 */
	@Override
	public CompanyInvoiceEntity getByCompanyName(Long companyId, String companyName) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("companyId", companyId);
		paramMap.put("companyName", companyName);
		return companyInvoiceDao.getByCompanyName(paramMap);
	}

}
